<?php

namespace app\admin\service\statistics\datatable\core;


use app\admin\service\statistics\datatable\AbstractComputeStatistician;
use app\admin\service\statistics\traits\CompletionTrait;


/**
 * 注册支付率
 * Class NewMemberPayRate
 * @package app\admin\service\statistics\datatable\fast
 */
class NewMemberPayRate extends AbstractComputeStatistician
{
    // 前置数据
    protected array $statisticians = [
        'member_count' => NewMemberCount::class,
        'pay_count' => PaySuccessCount::class,
    ];

    // 补齐
    use CompletionTrait;

    protected function compute(int $index)
    {
        $statisticiansData = $this->statisticiansData;

        $member_count = $statisticiansData['member_count'][$index]['value'] ?? null;

        $pay_count = $statisticiansData['pay_count'][$index]['value'] ?? null;

        if (!is_numeric($member_count) || !is_numeric($pay_count)) {
            return '';
        }

        return show_percentage($pay_count, $member_count, 1);
    }

    protected function getDefaultValue()
    {
        return '0%';
    }
}